<?php
/**
 * 功能描述：	用户登录注册模块
 * @datetime	2020-11-05
 * @version   	v1.0
 * @author   	ZHL
 * @copyrigh  	2020 ZHL 版权所有
 */

class Web_LoginServe extends Model {

    /**
     * Notes: 用户登录操作
     * User: ZhuHaili
     * Date: 2020/9/12
     * @return string
     */
	function goUserLogin($userName, $userPwd, $verifyCode){
		if(!$userName){
            return array('code'=>40001,'msg'=>'帐号不能为空');
        }
		if(!$userPwd){
            return array('code'=>40002,'msg'=>'密码不能为空');
        }
		if(!$verifyCode){
            return array('code'=>40003,'msg'=>'验证码不能为空');
        }
		$verifyCodeVal = SYS_SESSIONS_GET('w_img_code');
		if(!isset($verifyCodeVal['imgcode'])){
            return array('code'=>40004,'msg'=>'验证码不存在');
        }
		if($verifyCodeVal['imgcode'] != $verifyCode){
            return array('code'=>40005,'msg'=>'验证码错误');
        }
        $pwd = setPwd($userPwd);
        $login = new Web_LoginModel();
        // 昵称、手机、邮箱即可作为登录账号
        $find = $login->getUserInfoOther($userName, $pwd);
        if(empty($find)){
            return array('code'=>30000,'msg'=>'账号或密码错误');
        }
        if($find['status'] == 2){
            return array('code'=>30002,'msg'=>'账号异常已冻结');
        }else if($find['status'] == 3){
            return array('code'=>30003,'msg'=>'账号未激活');
        }else if($find['status'] == 4){
            return array('code'=>30004,'msg'=>'账号已注销');
        }
        $find['website_member'] = md5(md5(md5(SYS_HOST)));
        if(isset($find['pwd'])){
            unset($find['pwd']);
        }
        SYS_SESSIONS_SET('member_info', $find);
        return array('code'=>10000,'msg'=>'登录成功');
	}

    /**
     * Notes: 判断是否登录
     * User: ZhuHaili
     * Date: 2020/11/12
     */
    function judgeSessionLogin($type=''){
        $member_info = SYS_SESSIONS_GET('member_info');
        $member_infoId = isset($member_info['id']) ? $member_info['id'] : '';
        $member_infoWeb = isset($member_info['website_member']) ? $member_info['website_member'] : '';
        $webHttpUrl = md5(md5(md5(SYS_HOST)));
        if(!$member_infoId || ($member_infoWeb != $webHttpUrl)){
            if($type == 1){
                SYS_REDIRECT('login');
            }else{
                $url = SYS_HOST.'login.html';
                htmlAlert('超时！请重新登录',$url,3,1);
            }
        }
    }

    public function goset($param){
        SYS_SESSIONS_SET('test_info_s',$param);
    }

    public function goget(){
        return SYS_SESSIONS_GET('test_info_s');
    }
}